import { unstableSetRender } from 'antd-mobile'; // Support since version ^5.40.0
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
// import './index.css'
import App from './App.tsx';
import './globals.d';

createRoot(document.getElementById('root')!).render(
    <StrictMode>
        <App />
    </StrictMode>
);

interface WithReactRoot extends HTMLElement {
  _reactRoot?: ReturnType<typeof createRoot>;
}

unstableSetRender((node, container) => {
  const el = container as WithReactRoot;
  el._reactRoot ||= createRoot(el);
  const root = el._reactRoot!;
  root.render(node);

  return async () => {
    await new Promise((resolve) => setTimeout(resolve, 0));
    root.unmount();
    el._reactRoot = undefined;
  };
});